﻿<?php
// š
include_once('data.php');


if (isset($_GET['rev'])) {
	$mysqli = new mysqli(CONNECT_HOST, CONNECT_USER, CONNECT_PASS, CONNECT_DB);
	$mysqli->query("SET NAMES 'utf8'");

	$sql = "select line_id, line_direction, line_name, vehicle, active, line_revision, exceptional_ind, exceptional_desc from line where line_revision > ".$_GET['rev'].";";
	$result = $mysqli->query($sql);
	if (mysqli_num_rows($result) != 0) {
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
		echo "<linelist>\n";
		while ($row = $result->fetch_assoc()) {
			echo "\t<line line_id=\"" . $row["line_id"] . "\">\n";
			echo "\t\t<direction>" . $row["line_direction"] . "</direction>\n";
			echo "\t\t<line_name>" . $row["line_name"] . "</line_name>\n";
			echo "\t\t<vehicle>" . $row["vehicle"] . "</vehicle>\n";
			echo "\t\t<active>" . $row["active"] . "</active>\n";
			echo "\t\t<line_revision>" . $row["line_revision"] . "</line_revision>\n";
			echo "\t\t<exceptional_ind>" . $row["exceptional_ind"] . "</exceptional_ind>\n";
			echo "\t\t<exceptional_desc>" . $row["exceptional_desc"] . "</exceptional_desc>\n";
			
			$sql = "SELECT line_order, stop_id, stop_platform, distance_time, line_revision FROM linestops WHERE line_id = ".$row["line_id"]." and line_direction = ".$row["line_direction"].";";
			$result1 = $mysqli->query($sql);
			if (mysqli_num_rows($result1) != 0) {
				echo "\t\t<stoplist>\n";
				while ($row1 = $result1->fetch_assoc()) {
					echo "\t\t\t<stop stop_order=\"" . $row1["line_order"] . "\">\n";
					echo "\t\t\t\t<stop_id>" . $row1["stop_id"] . "</stop_id>\n";
					echo "\t\t\t\t<platform_id>" . $row1["stop_platform"] . "</platform_id>\n";
					echo "\t\t\t\t<distance_time>" . $row1["distance_time"] . "</distance_time>\n";
//					echo "\t\t\t\t<line_revision>" . $row1["line_revision"] . "</line_revision>\n";
					echo "\t\t\t</stop>\n";
				}
				echo "\t\t</stoplist>\n";
			}
			echo "\t</line>\n";
		}
		echo "</linelist>";
	} else {
		echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<linelist>\n</linelist>";	
	}
	$mysqli->close();
} else {
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<linelist>\n</linelist>";	
}
?>